package org.spring.blog.response;


import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.experimental.Accessors;


@Accessors(chain = true)
@Data
@AllArgsConstructor
public class ResponseResult {

    private boolean success;
    int code;
    private String message;
    private Object data;

    public ResponseResult() {
        success = true;
        code = ResponseState.success_code;
        message = ResponseState.success_message;
    }


    /**
     * 返回成功消息
     *
     * @return 返回消息类
     */
    public static ResponseResult success() {
        return new ResponseResult();
    }

    /**
     * 返回成功消息
     *
     * @param _message 信息提示
     * @return 返回消息类
     */
    public static ResponseResult success(String _message, int _code) {
        return new ResponseResult().setMessage(_message).setCode(_code);
    }

    /**
     * 返回成功消息
     *
     * @param _message 信息提示
     * @return 返回消息类
     */
    public static ResponseResult success(String _message) {
        return new ResponseResult().setMessage(_message);
    }

    /**
     * 返回失败信息
     *
     * @return 返回消息类
     */
    public static ResponseResult failed() {
        return new ResponseResult().setCode(ResponseState.failed_code)
                .setMessage(ResponseState.failed_message)
                .setSuccess(false);
    }

    /**
     * 返回失败信息
     *
     * @param _message 信息提示
     * @return 返回消息类
     */
    public static ResponseResult failed(String _message) {
        return failed().setMessage(_message);
    }

    /**
     * 返回失败信息
     *
     * @param _message 信息提示
     * @return 返回消息类
     */
    public static ResponseResult failed(String _message, int _code) {
        return failed().setMessage(_message).setCode(_code);
    }
}